<template>
  <div class="sidebar">
    <el-menu
        class="sidebar-el-menu"
        :collapse="collapse"
        background-color="#324157"
        text-color="#bfcbd9"
        active-text-color="#20a0ff"
        unique-opened
        router
    >

      <!--菜单项-->
      <template v-for="item in items">

        <!--含有子项-->
        <template v-if="item.subs">
          <el-sub-menu :index="item.index" :key="item.index">
            <template #title>
              <el-icon><component :is="item.icon"></component></el-icon>
              <span>{{ item.title }}</span>
            </template>
            <template v-for="subItem in item.subs">
              <el-menu-item :index="subItem.index">{{ subItem.title }}</el-menu-item>
            </template>
          </el-sub-menu>
        </template>

        <!--不含子项-->
        <template v-else>
          <el-menu-item :index="item.index" :key="item.index">
            <el-icon><component :is="item.icon"></component></el-icon>
            <template #title>{{ item.title }}</template>
          </el-menu-item>
        </template>

      </template>
    </el-menu>
  </div>
</template>

<script>
export default {
  name: "Sidebar",
  props: {
    collapse: {
      type: Boolean,
      default: false,
    },
    items: {
      type: Array,
      default: []
    }
  },
}
</script>

<style scoped>
.sidebar {
  display: block;
  position: absolute;
  left: 0;
  top: 70px;
  bottom: 0;
  overflow-y: scroll;
}
.sidebar::-webkit-scrollbar {
  width: 0;
}
.sidebar-el-menu:not(.el-menu--collapse) {
  width: 250px;
}
.sidebar > ul {
  height: 100%;
}
</style>